$(document).ready(function() {
	var winHeight = $('body').height();
		winHeight = winHeight-110;
	$('.service_search_box_table').height(winHeight).show();	
	
	var $rows = $('#service_search_table tr');
	$('#service_search-input').keyup(function() {
	    var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
	    
	    $rows.show().filter(function() {
	        var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
	        return !~text.indexOf(val);
	    }).hide();
	});
	
	$('#service_search_table td').click(function(e) {
		parent.returntext = $(this).text();
		parent.returnvalue = $(this).attr('data-return');
		parent.$.colorbox.close();		
		
        e.preventDefault();
        e.stopPropagation();
    });
	
	if($('.country').length > 0){
		var country_select = '<option value="0">Please select</option>';
		$.ajax({
			type: "GET",
			url: "js/country.xml",
			dataType: "xml",
			success: function(xml) {
				$(xml).find('country').each(function(){
					var id = $(this).attr('id');
					var title = $(this).text();
					
					if(title == 'Thailand'){
						country_select += '<option value="'+id+'"  selected="selected">'+title+'</option>';
					}else{
						country_select += '<option value="'+id+'">'+title+'</option>';
					}
				});
				$('.country').html(country_select);
			},
			error: function() {
			    alert("An error occurred while processing XML file.");
			}
		});	
	}
	if($('.province').length > 0){
		var province_select = '<option value="0">Please select</option>';
		$.ajax({
			type: "GET",
			url: "js/province.xml",
			dataType: "xml",
			success: function(xml) {
				$(xml).find('province').each(function(){
					var id = $(this).attr('id');
					var title = $(this).find('pname').text();
					
					province_select += '<option value="'+id+'">'+title+'</option>';
				});
				$('.province').html(province_select);
			},
			error: function() {
			    alert("An error occurred while processing XML file.");
			}
		});	
	}
	
	if($('.logline').length > 0){
		var totalheight = 10;
		$('.logtable').each(function(){
			var height = $(this).height();
			totalheight += height;
		});
		$('.logline').height(totalheight);
		$('.logmore').css('top',totalheight);
	}

    $( ".date-input" ).datepicker({
      dateFormat: 'dd-mm-yy',  
      showOn: "button",
      buttonImage: "/images/calendar.png",
      buttonImageOnly: true,
      buttonText: "เลือกวันที่",
        changeMonth: true,  
        changeYear: true      
    });	
    
    if($('.showTextFormLine').length > 0){
    	var height = $('.historyDetailZone').height();
    		height += 30;
    	$('.showTextFormLine').height(height);
    }
    
	$(document).on({
	    mouseleave: function(){
			$('.timeline-action-box').hide('blind');
	    }
    }, '.timeline-action-box');    
});
function openActionBox(){
	$('.timeline-action-box').show('blind');
}